<template>
  <section class="jumbotron">
    <h3 class="jumbotron-heading">Github用户搜索</h3>
    <div>
      <input type="text" placeholder="请输入用户名" v-model="keyword"/>&nbsp;
      <button @click="search">搜索</button>
    </div>
  </section>
</template>

<script>
  import axios from 'axios'
  export default {
    name:'Search',
    data() {
      return {
        keyword:''
      }
    },
    methods: {
      search(){
        // 1.拿着用户输入的关键词，发请求去搜索
        axios.get(`https://api.github.com/search/users?q=${this.keyword}`).then(
          // 请求成功的回调
          response => {
            // console.log('成功',response.data.items)
            // 触发$bus的user-list事件
            this.$bus.$emit('user-list',response.data.items)
          },
          // 请求失败的回调
          error => {
            console.log('失败',error.message)
          }
        )
        // 2.想办法把请求回来的用户数据交给List

      }
    },
  }
</script>